/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Ui;

import Model.Ausencia;
import Model.DB;
import Model.Estudiante;
import Model.Factura;
import Model.MyTableModel;
import java.awt.Color;
import java.awt.Font;
import java.awt.font.TextAttribute;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.StringTokenizer;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author William
 */
public class ModuloAlertas extends javax.swing.JFrame {

    DB db = new DB();
    String actual;

    public ModuloAlertas() {
        setExtendedState(MAXIMIZED_BOTH);
        initComponents();
        jPanel2.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelImagenEstudiante = new org.edisoncor.gui.panel.PanelImage();
        version = new javax.swing.JLabel();
        modulo = new javax.swing.JLabel();
        perfil = new javax.swing.JLabel();
        usuario = new javax.swing.JLabel();
        registrado = new javax.swing.JLabel();
        cerrarSesion = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelImagenEstudiante.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/BarraTituloFinal2.png"))); // NOI18N
        panelImagenEstudiante.setPreferredSize(new java.awt.Dimension(840, 60));

        version.setBackground(new java.awt.Color(255, 255, 255));
        version.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        version.setForeground(new java.awt.Color(255, 255, 255));
        version.setText("SMAMM 2.0");

        modulo.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        modulo.setForeground(new java.awt.Color(255, 255, 255));
        modulo.setText("Módulo Alertas");

        perfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/SignedAs.png"))); // NOI18N

        usuario.setForeground(new java.awt.Color(255, 255, 255));
        usuario.setText("1235");

        registrado.setForeground(new java.awt.Color(255, 255, 255));
        registrado.setText("Registrado(a) como:");

        cerrarSesion.setForeground(new java.awt.Color(255, 255, 255));
        cerrarSesion.setText("Cerrar sesión");
        cerrarSesion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                cerrarSesionMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                cerrarSesionMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                cerrarSesionMousePressed(evt);
            }
        });

        javax.swing.GroupLayout panelImagenEstudianteLayout = new javax.swing.GroupLayout(panelImagenEstudiante);
        panelImagenEstudiante.setLayout(panelImagenEstudianteLayout);
        panelImagenEstudianteLayout.setHorizontalGroup(
            panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelImagenEstudianteLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(modulo, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(207, 207, 207)
                .addComponent(version)
                .addGap(158, 158, 158)
                .addComponent(perfil)
                .addGroup(panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImagenEstudianteLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(registrado)
                        .addGap(26, 26, 26)
                        .addComponent(usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelImagenEstudianteLayout.createSequentialGroup()
                        .addGap(101, 101, 101)
                        .addComponent(cerrarSesion)))
                .addGap(41, 41, 41))
        );
        panelImagenEstudianteLayout.setVerticalGroup(
            panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImagenEstudianteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImagenEstudianteLayout.createSequentialGroup()
                        .addGroup(panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(registrado)
                            .addComponent(usuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cerrarSesion)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelImagenEstudianteLayout.createSequentialGroup()
                        .addGroup(panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(modulo)
                            .addGroup(panelImagenEstudianteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(version, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(perfil, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Cedula", "Nombre", "Estado", "Ultimo pago", "Ultima ausencia", "Telefono", "Email", "Tel Responsable ", "Observaciones"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Actualizar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText(" Fechas en formato :(año/mes/dia)");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        jButton2.setText("Volver");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setText("Email:");

        jTextField1.setEditable(false);

        jLabel3.setText("Telefono:");

        jTextField2.setEditable(false);

        jLabel4.setText("Telefono 2:");

        jTextField3.setEditable(false);

        jTextField4.setEditable(false);

        jLabel5.setText("Email Responsable:");

        jLabel6.setText("Telefono Responsable:");

        jTextField5.setEditable(false);

        jButton3.setText("Ocultar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextField4))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(jLabel6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jButton3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addGap(8, 8, 8)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1175, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jLabel1)
                        .addComponent(jButton2))
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelImagenEstudiante, javax.swing.GroupLayout.DEFAULT_SIZE, 1185, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelImagenEstudiante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cerrarSesionMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cerrarSesionMouseEntered
        // TODO add your handling code here:
        Font font = new Font("Tahoma", Font.PLAIN, 11);
        Map attributes = font.getAttributes();
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        cerrarSesion.setFont(font.deriveFont(attributes));
        cerrarSesion.setForeground(new Color(0, 0, 204));
    }//GEN-LAST:event_cerrarSesionMouseEntered

    private void cerrarSesionMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cerrarSesionMouseExited
        // TODO add your handling code here:
        cerrarSesion.setFont(new Font("Tahoma", Font.PLAIN, 11));
        cerrarSesion.setForeground(new Color(0, 0, 0));
    }//GEN-LAST:event_cerrarSesionMouseExited

    private void cerrarSesionMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cerrarSesionMousePressed
        // TODO add your handling code here:
        VentanaPrincipal ob = new VentanaPrincipal();
        ob.setVisible(true);
        dispose();
    }//GEN-LAST:event_cerrarSesionMousePressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //JOptionPane.showMessageDialog(null, getMesActual());
        ArrayList<Estudiante> res = db.listarEstudiantes();
        String[] columnNames = new String[]{"Cedula", "Nombre", "Estado(Ausencias)", "Ultima Ausencia", "Estado(Pagos)", "Ultimo pago", "Observaciones", "Informacion de contacto"};
        Object[][] data = new Object[][]{};
        //TablaImagen t = new TablaImagen(columnNames);

        MyTableModel modelo = new MyTableModel(data, columnNames);
        String[] color = null;
        String[] ausencias;
        String pagos = "";
        for (Estudiante u : res) {
            ausencias = alerta2(u.getId());
            //  JOptionPane.showMessageDialog(null, u.getId()+ " color de ausencia "+ ausencias[0]);
            color = alerta(u.getId());
            if (color != null) {

                pagos = color[0];
                if (pagos != null) {
                    if (pagos.equals("verde")) {
                        pagos = "/Img/verde.png";
                    }
                    if (pagos.equals("amarillo")) {
                        pagos = "/Img/amarillo.png";
                    }
                    if (pagos.equals("rojo")) {
                        pagos = "/Img/rojo.png";
                    }
                    if (pagos.equals("naranja")) {
                        pagos = "/Img/naranja.png";
                    }
                }
            }

            if (pagos == null) {
                if (ausencias[0] == null) {
                    modelo.addRow(new Object[]{u.getId(), u.getNombre(), createImage("/Img/puntos.png"), ultimaAusencia(u.getId()), createImage("/Img/puntos.png"), ultimoPago(u.getId()), "Sin observaciones", createImage("/Img/eye.png")});
                } else {
                    modelo.addRow(new Object[]{u.getId(), u.getNombre(), createImage(ausencias[0]), ultimaAusencia(u.getId()), createImage("/Img/puntos.png"), ultimoPago(u.getId()), ausencias[1], createImage("/Img/eye.png")});
                }
            } else {
                // JOptionPane.showMessageDialog(null, c);
                if (ausencias[0] == null) {
                    modelo.addRow(new Object[]{u.getId(), u.getNombre(), createImage("/Img/puntos.png"), ultimaAusencia(u.getId()), createImage(pagos), ultimoPago(u.getId()), color[1], createImage("/Img/eye.png")});
                } else {
                    modelo.addRow(new Object[]{u.getId(), u.getNombre(), createImage(ausencias[0]), ultimaAusencia(u.getId()), createImage(pagos), ultimoPago(u.getId()), color[1] + " / " + ausencias[1], createImage("/Img/eye.png")});
                }
            }

            // modelo.addRow(new Object[]{u.getId(), u.getNombre(), u.getPApellido() + " " + u.getSApellido(), createImage("/Img/eye.png"), createImage("/Img/modi.png"), createImage("/Img/delete.png")});
        }
        //jTable1.getColumnModel().getColumn(4).setWidth(100);
        jTable1.setRowHeight(30);
//        TableColumn columna = jTable1.getColumn("Observaciones");
//        columna.setPreferredWidth(30) ;
//        columna.setMinWidth(30);
//        jTable1.getColumnModel().getColumn(8).setPreferredWidth(300);
//         jTable1.getColumnModel().getColumn(2).setPreferredWidth(40);
        jTable1.setModel(modelo);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(400);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(30);
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(30);
        //jTable1.setEnabled(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if (actual.contains("E")) {
            VentanaPrincipalEstandar2 s = new VentanaPrincipalEstandar2();
            s.setUserActual(actual);
            s.setVisible(true);
            this.dispose();

        }
        if (actual.contains("A")) {
            VentanaModuloAdministrador s = new VentanaModuloAdministrador();
            s.setUserActual(actual);
            s.setVisible(true);
            this.dispose();

        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
//        JOptionPane.showMessageDialog(null, "asdasd");
    }//GEN-LAST:event_jLabel1MouseClicked

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked

        if (jTable1.getSelectedColumn() == 7) {
            String ced = (String) jTable1.getValueAt(jTable1.getSelectedRow(), 0);
            Estudiante e = db.listarEstudiante(ced);
            jTextField1.setText(e.getEmail());
            jTextField2.setText(e.getTel() + "");
            jTextField3.setText(e.getTel2() + "");
            jTextField4.setText(e.getEmail_Responsable());
            jTextField5.setText(e.getTel_responsable() + "");
            jPanel2.setVisible(true);
        }


    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        jPanel2.setVisible(false);
        jPanel1.validate();
        jPanel1.repaint();
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModuloAlertas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModuloAlertas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModuloAlertas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModuloAlertas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModuloAlertas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cerrarSesion;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JLabel modulo;
    private org.edisoncor.gui.panel.PanelImage panelImagenEstudiante;
    private javax.swing.JLabel perfil;
    private javax.swing.JLabel registrado;
    private javax.swing.JLabel usuario;
    private javax.swing.JLabel version;
    // End of variables declaration//GEN-END:variables
    Calendar fecha = new GregorianCalendar();

    public ImageIcon createImage(String path) {
        URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    public String[] alerta(String user) {
        String[] res = new String[2];
        String ultimoPago = ultimoPago(user);
        //JOptionPane.showMessageDialog(null, ultimoPago + " cedula "+user);

        if (ultimoPago != null && !ultimoPago.equals("")) {
            int dia = getDiaActual(), mes = getMesActual() + 1, diaP = getDia(ultimoPago), mesP = getMes(ultimoPago);
//JOptionPane.showMessageDialog(null, "dia" + dia+ " mes"+ mes+" diap "+diaP+" mesp"+mesP);
            if (db.pagoMesActual(user, mes, getAnnioActual())) {
                res[0] = "verde";
                res[1] = "mes " + mesNum(mes) + " cancelado";
            } /*else if (dia >= 1 && dia <= 31 && diaP >= 1 && diaP <= 7 && mes == mesP) {
             res[0] = "verde";
             // JOptionPane.showMessageDialog(null, ultimoPago + " cedula " + user + " a este le deberia de aparecer verde");
             res[1] = "pagó la primera semana del mes";
             }*/ else if (mesP < mes) {
                int resta = mes - mesP;
                if (dia >= 8) {
                    res[0] = "naranja";
                    if (resta == 1) {
                        if (db.pagoMesActual(user, mesP, getAnnioActual())) {

                            res[1] = "pago el mes pasado pero este aun no,\n y ya paso una semana o mas";
                        }

                    } else if (resta == 2) {
                        res[1] = "debe un mes o mas...";
                        res[0] = "rojo";
                    }

                } else if (dia <= 7) {
                    res[0] = "amarillo";
                    if (resta == 1) {
                        res[1] = "pago el mes pasado pero este aun no";
                    } else if (resta == 2) {
                        res[1] = "no ha pagado el mes pasado, ni este";
                    }
                } else if (diaP >= 24 && resta == 1) {
                    res[0] = "verde";
                    // JOptionPane.showMessageDialog(null, ultimoPago + " cedula " + user + " a este le deberia de aparecer verde");
                    res[1] = "pagó la ultima semana del mes pasado";
                }
                //  JOptionPane.showMessageDialog(null, resta);
                if (resta > 1) {
                    res[0] = "rojo";
                    //JOptionPane.showMessageDialog(null, user + mesP);
                    for(int i = mesP;i!=mes;i++){
                         if (db.pagoMesActual(user, i, getAnnioActual())) {

                        res[1] = "debe un mes o mas(ultimo pagado " + mesNum(i) + ")...";
                    }
                    }
                   
//                    } else {
//                        res[1] = "debe un mes o mas...";
//                    }
                }

            }

        }
        return res;
    }

    public String mesNum(int n) {
        switch (n) {
            case 1:
                return "Enero";
            case 2:
                return "Febrero";
            case 3:
                return "Marzo";
            case 4:
                return "Abril";
            case 5:
                return "Mayo";
            case 6:
                return "Junio";
            case 7:
                return "Julio";
            case 8:
                return "Agosto";
            case 9:
                return "Setiembre";
            case 10:
                return "Octubre";
            case 11:
                return "Noviembre";
            case 12:
                return "Diciembre";

        }
        return "";
    }

    public String[] alerta2(String user) {
        String[] res = new String[2];
        ArrayList<Ausencia> ausenciasM = db.listarAusenciasMes(user, getMesActual() + 1);
        if (ausenciasM != null) {
            if (!ausenciasM.isEmpty()) {
                switch (ausenciasM.size()) {
                    case 1: {
                        res[0] = "/Img/amarillo.png";
                        res[1] = "1 ausencia en el actual mes";
                        break;
                    }
                    case 2: {
                        res[0] = "/Img/naranja.png";
                        res[1] = "2 ausencias en el actual mes";
                        break;
                    }
                    case 3: {
                        res[0] = "/Img/rojo.png";
                        res[1] = "3 ausencias en el actual mes";
                        break;
                    }
                    case 4: {
                        res[0] = "/Img/rojo.png";
                        res[1] = "4 ausencias en el actual mes";
                        break;
                    }
                }
            } else {
                //JOptionPane.showMessageDialog(null, user + " tiene la lista vacia ");
            }
        } else {
            // JOptionPane.showMessageDialog(null, user + " tiene la lista nula ");
        }

        return res;
    }

    public int getMesActual() {
        return fecha.get(Calendar.MONTH);
    }

    public int getDiaActual() {
        return fecha.get(Calendar.DAY_OF_MONTH);
    }

    public int getAnnioActual() {
        return fecha.get(Calendar.YEAR);
    }

    public int getAnnio(String date) {
        String delim = "-";
        StringTokenizer tok = new StringTokenizer(date, delim, true);
        String res = tok.nextToken();
        //JOptionPane.showMessageDialog(null, date +" año"+ res);
        return Integer.parseInt(res);
    }

    public int getMes(String date) {
        String delim = "-";
        StringTokenizer tok = new StringTokenizer(date, delim, true);
        tok.nextToken();
        tok.nextToken();
        String res = tok.nextToken();
        //JOptionPane.showMessageDialog(null, date +" mes "+ res);
        return Integer.parseInt(res);
    }

    public int getDia(String date) {
        String delim = "-";
        StringTokenizer tok = new StringTokenizer(date, delim, true);
        tok.nextToken();
        tok.nextToken();
        tok.nextToken();
        tok.nextToken();
        String res = tok.nextToken();
        // JOptionPane.showMessageDialog(null, date +" dia "+ res);
        return Integer.parseInt(res);
    }

    public String ultimaAusencia(String user) {
        ArrayList<Ausencia> res = db.listarAusencias(user);
        String aux = "";

        if (!res.isEmpty()) {
            aux = res.get(0).getFecha();
            for (Ausencia a : res) {
                if (getAnnio(a.getFecha()) > getAnnio(aux)) {
                    aux = a.getFecha();
                } else if (getAnnio(a.getFecha()) == getAnnio(aux) && getMes(a.getFecha()) > getMes(aux)) {
                    aux = a.getFecha();
                } else if (getAnnio(a.getFecha()) == getAnnio(aux) && getMes(a.getFecha()) == getMes(aux) && getDia(a.getFecha()) > getDia(aux)) {
                    aux = a.getFecha();
                }
            }
        }
        return aux;
    }

    public String ultimoPago(String user) {
        ArrayList<Factura> res = db.listarFacturas(user);
        String aux = "";

        if (!res.isEmpty()) {
            aux = res.get(0).getFecha();
            for (Factura a : res) {
                // JOptionPane.showMessageDialog(null, aux);
                if (getAnnio(a.getFecha()) > getAnnio(aux)) {
                    aux = a.getFecha();
                } else if (getAnnio(a.getFecha()) == getAnnio(aux) && getMes(a.getFecha()) > getMes(aux)) {
                    aux = a.getFecha();
                } else if (getAnnio(a.getFecha()) == getAnnio(aux) && getMes(a.getFecha()) == getMes(aux) && getDia(a.getFecha()) > getDia(aux)) {
                    aux = a.getFecha();
                }
            }
        }
        return aux;
    }

    void setActual(String userActual) {
        actual = userActual;
        usuario.setText(actual);

    }
}
